 package com.wyz.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;

import com.wyz.entity.Movie;
import com.wyz.entity.User;
import com.wyz.json.Jackson;
import com.wyz.service.MovieService;
import com.wyz.service.UserService;

import my.mvc.IUser;
import my.mvc.RequestContext;
import my.util.ResponseUtils;

public class MovieAction {
	
	MovieService movieService = new MovieService();
	UserService userService=new UserService();
	public void findByType(RequestContext rc) throws ServletException, IOException{
		Long typeId = rc.param("typeId",-1L);
		
		//System.out.println(typeId);
		
		List<Movie> list = movieService.findByType(typeId);
		
		String json = Jackson.me().toJson(list);
		ResponseUtils.renderJson(rc.response(), json);
	}
	public void movieInfo(RequestContext rc)  throws ServletException, IOException{
		
		Long id=rc.param("id",0L);
		//System.out.println(id);
		Movie movie =movieService.findById(id);
		
		IUser iuser=rc.getUserFromCookie();
		
		if(iuser!=null) {
			User user=userService.findById(iuser.getId());
			rc.reqAttr("user",user);
			System.out.println("目前用户为"+user.getUserName());
		}
		
		rc.reqAttr("movie",movie);
		rc.forward("/pages/movie.jsp");
		
	}
	
	
	
	
}
